﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using vnCommonGUI;
using vnFingerPrint.DataAccess;
using vnFingerPrint.BusinessObject;
namespace vnFingerPrint.GUI
{
    public partial class FrmMain : Form
    {
        Users_Object User;
        frmLogin fl = new frmLogin();
        public static FrmMain Instance=null;
        public FrmMain()
        {
            InitializeComponent();
            Instance = this;
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            fl = new frmLogin();
            fl.ShowDialog();
            if (fl.pass < 1)
            {
                //this.Close();
                Application.Exit();
            }
            else
            {
                LoadUser();
            }
        }
        public void LoadUser()
        {
            User = UserLogIn.userLogedIn;
            try
            {
                pbChanDung.Image = new Bitmap(new Bitmap(Config_DataAccess.GetUserImagePath(User.ImageUrl)), new Size(512, 512));
            }
            catch
            {
            }
            lblHoten.Text = "Họ tên:\t" + User.FullName;
            lblTenDangNhap.Text = "Tên đăng nhập:\t" + User.UserName;
            lblChucVu.Text = "Chức vụ:\t" + User.ChucVu;
            lblDonVi.Text = "Đơn vị:\t" + User.DonViCongTac;
            if (Permission_DataAccess.Find(UserLogIn.userLogedIn.PermissionId).Role != "admin")
            {
                btnUserManager.Enabled = false;
                btnNhapCongDan.Enabled = false;
                tàiKhoảnNgườiDùngToolStripMenuItem.Enabled = false;
                quảnLýCôngDânToolStripMenuItem.Enabled = false;
            }
            else
            {
                btnUserManager.Enabled = true;
                btnNhapCongDan.Enabled = true;
                tàiKhoảnNgườiDùngToolStripMenuItem.Enabled = true;
                quảnLýCôngDânToolStripMenuItem.Enabled = true;
            }
            fl.Close();
            fl.Dispose();
        }
        private void btn1vs1_Click(object sender, EventArgs e)
        {
            Frm1vs1Compare f = new Frm1vs1Compare();
            f.Show();
        }

        private void btnSteps_Click(object sender, EventArgs e)
        {
            FrmTest f = new FrmTest();
            f.Show();
        }

        private void btnUserManager_Click(object sender, EventArgs e)
        {
            UsersManagement um = new UsersManagement();
            um.Show();
        }

        private void btnNhapCongDan_Click(object sender, EventArgs e)
        {
            frmQuanLyCongDan cd = new frmQuanLyCongDan();
            cd.ShowDialog();
        }

        private void btn1_N_Click(object sender, EventArgs e)
        {
            //frmDoiSanh1_N cd = new frmDoiSanh1_N();
            //cd.ShowDialog();
            frmNeuralNetwork NN = new frmNeuralNetwork();
            NN.ShowDialog();
        }

        private void tàiKhoảnNgườiDùngToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnUserManager_Click(null,null);
        }

        private void phươngPhápMạngNeuralToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmNeuralNetwork NN = new frmNeuralNetwork();
            NN.ShowDialog();
        }

        private void thoátToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnExit_Click(null,null);
        }

        private void mnLogout_Click(object sender, EventArgs e)
        {
            try
            {
                UserLogIn.userLogedIn = null;
                Hide();
                fl = new frmLogin();
                fl.ShowDialog();
            }
            catch { }
            
        }

        private void btnLogout_Click(object sender, EventArgs e)
        {
            mnLogout_Click(sender, e);
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Bạn có chắc chắn muốn thoát chương trình ?","Xác nhấn thoát",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
            this.Close();
        }

        private void quảnLýCôngDânToolStripMenuItem_Click(object sender, EventArgs e)
        {
            btnNhapCongDan_Click(sender, e);
        }
    }
}
